<%@ page import="java.io.* , java.util.*, java.sql.*, com.myapp.struts.dao.* , com.myapp.struts.actionform.*, com.myapp.struts.beans.*" %>
<html>
    <head>
        <title>Item Master</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <link href="../../../../css/cms.css" rel="stylesheet" type="text/css">
    </head>

    <body>
        <% String accountHead;
             String pd1;
             String pm1;
             String py1;
             String date;
             String pd2;
             String pm2;
             String py2;
             String date1;
                                pd1   = request.getParameter("daydropdown");
                    pm1   = request.getParameter("monthdropdown");
                    py1   = request.getParameter("yeardropdown");

                    pd2   = request.getParameter("daydropdown2");
                    pm2   = request.getParameter("monthdropdown2");
                    py2   = request.getParameter("yeardropdown2");
                    accountHead=request.getParameter("achead");
                    date  = py1 + "-" + pm1 + "-" + pd1;
                                date1 = py2 + "-" + pm2 + "-" + pd2;
                    String acheadtype="",openingBalance="";
                    AcheadDao imdao = new AcheadDao();
                    ArrayList gp    = imdao.acheadDetails(accountHead);
                    if (gp != null) {
                        Iterator itin = gp.iterator();

                        while (itin.hasNext()) {
                            AccountHeadBean gb = (AccountHeadBean) itin.next();

                            /** Selected Account Head  Opening balance and entry type */

                            acheadtype     = gb.getDescription();
                            openingBalance = gb.getOBalance();
                            System.out.println("openingBalance=" + openingBalance);
                        }
                    }
        %>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <th colspan="8" scope="col">Ledger</th>
            </tr>
            <tr>
                <td colspan="2">Account Head</td>
                <td colspan="2"><%=accountHead%></td>
                <td colspan="4">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="2">Account Type</td>
                <td colspan="2"><%=acheadtype%></td>
                <td colspan="4">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="4" align="right"><strong>Dr</strong></td>
                <td colspan="4" align="right"><strong>Cr</strong></td>
            </tr>
            <tr>
                <th width="12%" height="24">Date</th>
                <th width="12%">Description</th>
                <th width="8%">Ref</th>
                <th width="17%">Amount</th>
                <th width="13%" height="24">Date</th>
                <th width="17%">Description</th>
                <th width="7%">Ref</th>
                <th width="14%">Amount</th>
            </tr>
            <tr>
                <td height="24" colspan="4" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <%
                         double crtotal=0.00,drtotal=0.00,total=0.00;
                             LedgerDao ldao1 = new LedgerDao();
                           Vector tv = ldao1.getTotalAndClosing(openingBalance, accountHead);
                           if (tv != null) {
                               crtotal=Double.parseDouble(tv.elementAt(0).toString());
                               drtotal=Double.parseDouble(tv.elementAt(1).toString());
                               total=Double.parseDouble(tv.elementAt(2).toString());
                               System.out.println("crtotal="+crtotal);
                               System.out.println("drtotal="+drtotal);
                               System.out.println("total="+total);
                                           }
                        %>
                        <%
                    String voucherDate="",description="",reference="",amount="";
  
                    LedgerDao rvdao = new LedgerDao();
                          Vector rv = rvdao.list(accountHead,"Dr",date,date1);
                          if (rv != null) {
                              System.out.println("Not Null rececipts");
                              Iterator itg = rv.iterator();
                              while (itg.hasNext()) {
                                  LedgerBean gb = (LedgerBean) itg.next();
                                  voucherDate = gb.getVoucherDate();
                                  description = gb.getDescription();
                                  reference=gb.getRef();
                                  amount = gb.getAmount();
                        %>
                        <tr>
                            <td width="24%" align="center"><%=voucherDate%></td>
                            <td width="25%"><%=description%></td>
                            <td width="16%" align="center"><%=reference%></td>
                            <td width="35%" align="right"><%=amount%></td>
                        </tr>
                        <%    }
      }  %>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <%if (drtotal<crtotal)
            {
                        %>
                        <tr>
                            <td width="24%" align="center">&nbsp;</td>
                            <td width="25%">Closing Balance</td>
                            <td width="16%" align="center">&nbsp;</td>
                            <td width="35%" align="right"><%=(crtotal-drtotal)%></td>
                        </tr>
                        <%}%>

                        <tr>
                            <td align="center">&nbsp;</td>
                            <td>Total Amount</td>
                            <td align="center">&nbsp;</td>
                            <td align="right"><%=total%></td>
                        </tr>

                    </table>



                </td>
                <td height="24" colspan="4" valign="bottom"><table width="100%" border="0" cellspacing="0" cellpadding="0">


                        <%  LedgerDao ldao = new LedgerDao();
                         Vector cr= ldao.list(accountHead,"Cr",date,date1);
                          if (cr != null) {
                              System.out.println("Not Null rececipts");
                              Iterator itg = cr.iterator();
                              while (itg.hasNext()) {
                                  LedgerBean gb1 = (LedgerBean) itg.next();
                                  voucherDate = gb1.getVoucherDate();
                                  description = gb1.getDescription();
                                  reference=gb1.getRef();
                                  amount = gb1.getAmount();
                        %>
                        <tr>
                            <td width="25%" align="center"><%=voucherDate%></td>
                            <td width="34%"><%=description%></td>
                            <td width="14%"><%=reference%></td>
                            <td width="27%" align="right"><%=amount%></td>
                        </tr>
                        <%}
                      }
                        %>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">

                        <% if (drtotal>crtotal)
	  {%>
                        <tr>
                            <td width="25%" align="center">&nbsp;</td>
                            <td width="34%">Closing Balance</td>
                            <td width="14%">&nbsp;</td>
                            <td width="27%" align="right"><%=(drtotal-crtotal)%></td>
                        </tr>
                        <%}%>
                        <tr>
                            <td align="center">&nbsp;</td>
                            <td>Total Amount</td>
                            <td>&nbsp;</td>
                            <td align="right"><%=total%></td>
                        </tr>



                    </table></td>
            </tr>
        </table>
    </body>
</html>